import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'
import UserList from '@/views/user/UserList'


import Login from '@/components/Login'



Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Home,
      beforeEnter (to, from, next) {
        // 是否登录，没有登录跳转到登录页，进行登录
        let username = sessionStorage.getItem('username')
        if(username) {
          next()
        }else{
          alert('没有登录，不能访问')
          next('/login')
        }
      },
      children:[{
        path: '/userlist',
        component: UserList
      }]
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    }
  ]
})
